package wt.hpad.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.CheckBox;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wt on 1.11.
 */

public class SimpleCheckboxDialog extends SimpleDialog {


    public SimpleCheckboxDialog(Context mContext, Activity mActivity, int mRootViewid, int mBtnConfirmViewid, int mBtnCancelViewid) {
        super(mContext, mActivity, mRootViewid, mBtnConfirmViewid, mBtnCancelViewid);
    }

    public SimpleCheckboxDialog(Activity activity, int rootViewid) {
        super(activity,rootViewid);
    }


    public List<CheckBox> createCheckboxList(int[] cbIds) {
        List<CheckBox> checkBoxes = new ArrayList<>();
        View rootView = getRootView();
        for (int i = 0; i < cbIds.length; i++) {
            checkBoxes.add((CheckBox) (rootView.findViewById(cbIds[i])));
        }
        return checkBoxes;
    }

    public String getCheckedTexts(int[] cbIds, String splitMark) {
        StringBuilder builder = new StringBuilder();
        List<CheckBox> checkBoxes = this.createCheckboxList(cbIds);

        for (CheckBox item : checkBoxes) {
            if (item.isChecked()) {
                String value = item.getText().toString();
                builder.append(value);
                builder.append(splitMark);
            }
        }
        if (builder.length() != 0) {
            builder.deleteCharAt(builder.length() - 1);
        }
        return builder.toString();
    }
}
